{{- $currentNode := . }}
{{- range where .Site.Home.Sections.ByDate "Type" "blog"}}
{{- template "section-blog-tree-nav" dict "sect" . "currentnode" $currentNode}}
{{- end }}

<!-- templates -->
{{- define "section-blog-tree-nav" }}

{{- $currentNode := .currentnode }}
 {{- with .sect}}
  {{- if and .IsSection (or (not .Params.hidden) $.showhidden)}}
    {{- $numberOfPages := (add (len .Pages) (len .Sections)) }}
    {{- safeHTML .Params.head}}

    <li data-nav-id="{{.URL}}" class="dd-item
        {{- if .IsAncestor $currentNode}} parent{{end}}
        {{- if eq .URL $currentNode.URL}} active{{end}}
        {{- if .Params.alwaysopen}} alwaysopen{{end -}}
        {{- if ne $numberOfPages 0 }} haschildren{{end}}
        ">
        {{if eq .Name "博客"}}
          {{else}}
          <div>
            {{- if ne $numberOfPages 0 }}
              <a class="category" href="javascript:void(0)">
                <div>{{safeHTML  .Params.Pre}}{{.Title}}{{safeHTML .Params.Post}}</div>
                <div class="date">({{$numberOfPages}})</div>
              </a>
              {{else}}
              <a href="{{ .RelPermalink}}">{{safeHTML  .Params.Pre}}{{.Title}}{{safeHTML .Params.Post}}</a>
            {{end}}
            {{- if ne $numberOfPages 0 }}
              {{- if or (.IsAncestor $currentNode) (.Params.alwaysopen) }}
                <i class="iconfont caret-down category-icon">&#xe639;</i>
                {{- else -}}
                <i class="iconfont caret-right category-icon">&#xe66f;</i>
              {{- end}}
            {{- end}}
          </div>
        {{end}}
        {{- if ne $numberOfPages 0 }}
          <ul>
            {{- .Scratch.Set "pages" .Pages }}
            {{- if .Sections}}
            {{- .Scratch.Set "pages" (.Pages | union .Sections) }}
            {{- end}}
            {{- $pages := (.Scratch.Get "pages") }}

            {{- range $pages.ByWeight }}
              {{- if and .Params.hidden (not $.showhidden) }}
              {{- else}}
              {{- template "section-blog-tree-nav" dict "sect" . "currentnode" $currentNode}}
              {{- end}}
            {{- end}}
          </ul>
        {{- end}}
    </li>
    {{- else}}
    {{- if not .Params.Hidden }}
    <li data-nav-id="{{.URL}}" class="dd-item
    {{- if eq .URL $currentNode.URL}} active{{end -}}
    ">
      <div>
        <a href="{{ .RelPermalink}}">
          {{safeHTML .Params.Pre}}{{.LinkTitle}}{{safeHTML .Params.Post}}
        </a>
      </div>
    </li>
     {{- end}}
  {{- end}}
 {{- end}}
{{- end}}
